#ifndef _BARTER_SERVER_NETWORKSYSTEM_H_
#define _BARTER_SERVER_NETWORKSYSTEM_H_

#include <boost/noncopyable.hpp>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <list>

#include "Connection.h"

enum NetworkSystemStatus
{
	STATUS_STOPPED,
	STATUS_RUNNING,
};

class NetworkSystem : boost::noncopyable
{
private:
	NetworkSystem();
	~NetworkSystem();
	void OnAccept();
	void Accept();
	std::list<Connection*> Connections;
	boost::asio::io_service IOService;
	boost::asio::ip::tcp::acceptor* ListenSocket;
	boost::recursive_mutex Mutex;
	int Status;
	std::string ListenHost;
	int ListenPort;
public:
	NetworkSystem& Instance();
	void Init();
	void Run();
	void Stop();
	int GetStatus();
	void Close(Connection*);
	void CloseAllConnections();
};

#define netSys NetworkSystem::Instance()

#endif // _BARTER_SERVER_NETWORKSYSTEM_H_
